package com.edu.exam.enums.curriculum.questionbank;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 验证规则类型枚举
 */
public enum ValidationRuleType implements BaseEnum {
    REQUIRED("REQUIRED", "必填验证"),
    FORMAT("FORMAT", "格式验证"),
    RANGE("RANGE", "范围验证"),
    LENGTH("LENGTH", "长度验证"),
    PATTERN("PATTERN", "模式验证"),
    CUSTOM("CUSTOM", "自定义验证"),
    BUSINESS("BUSINESS", "业务验证"),
    COMPLEXITY("COMPLEXITY", "复杂度验证"),
    UNIQUENESS("UNIQUENESS", "唯一性验证"),
    REFERENCE("REFERENCE", "引用验证");

    private final String code;
    private final String description;

    ValidationRuleType(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    public static ValidationRuleType fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("ValidationRuleType code cannot be null or empty");
        }
        for (ValidationRuleType type : values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown ValidationRuleType code: " + code);
    }

    public static ValidationRuleType fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("ValidationRuleType description cannot be null or empty");
        }
        for (ValidationRuleType type : values()) {
            if (type.getDescription().equals(description)) {
                return type;
            }
        }
        throw new IllegalArgumentException("Unknown ValidationRuleType description: " + description);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}